package com.spring.sunflower;

import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.spring.sunflower.encrypt.DataEncryptUtils;
import com.spring.sunflower.util.LogUtils;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * Created by Kevin on 2021/11/18<br/>
 * <p>
 * Describe:<br/>
 */
public class ResponseBodyConverter<T> implements Converter<ResponseBody,T> {
    private TypeAdapter<T> adapter;
    private Gson gson;

    public ResponseBodyConverter(TypeAdapter<T> adapter) {
        this.adapter = adapter;
    }

    public ResponseBodyConverter(TypeAdapter<T> adapter, Gson gson) {
        this.adapter = adapter;
        this.gson = gson;
    }

    @Nullable
    @Override
    public T convert(ResponseBody value) throws IOException {
        String string = value.string().replace("\"","");
        LogUtils.INSTANCE.logI("AppRetrofit", "好吧" + string);
        return adapter.fromJson(DataEncryptUtils.dataDecrypt(string));
    }
}
